<template>
	<!-- #ifdef H5 -->
	<div v-html="html">

	</div>
	<!-- #endif -->
</template>

<script>
	export default {
		onLoad(options) {
			this.id = options.id
		},
		mounted() {
			const result = uni.getStorage("weixinCallback");
			if (result != 3) { //这是弄了个变量来判断是否已经进入了支付，防止用户直接左滑的返回一直在触发支付
				this.alipay()
			}
		},
		data() {
			return {
				html: "",
				id: "",
			};
		},
		methods: {
			alipay() {
				this.$Api['user'].moneyRecharge({
					recharge_id: this.id,
					paytype: 'alipay',
					method: 'wap'
				}).then(res => {
					//将表单渲染进页面
					document.querySelector('body').innerHTML = res.data;
					//在渲染完立即提交表单，就会进入支付宝支付的界面
					this.$nextTick(() => {
						uni.setStorage("weixinCallback", 3);
						window.document.forms[0].submit()
					})
				})
			}
		}
	};
</script>